﻿using System;
using System.Data;
using Moq;
using JTLeigh.Commerce.Spencer.Core.Data.Services;
using JTLeigh.Commerce.Spencer.Core.Common;

namespace JTLeigh.Commerce.Spencer.Core.Testing.Mocks.Data
{

	/// <summary>
	/// Mock database connection factory.
	/// </summary>
	[CLSCompliant(false)]
	public class MockDatabaseConnectionFactory : Mock<IDatabaseConnectionFactory>
	{

		#region Constructors

		/// <summary>
		/// Initializes a new instance of the <see cref="MockDatabaseConnectionFactory"/> class 
		/// with the specified tenant identifier, database key, and connection.
		/// </summary>
		/// <param name="tenantId">The tenant identifier.</param>
		/// <param name="databaseKey">The database key.</param>
		/// <param name="connection">The <see cref="IDbConnection"/> to return when 
		/// <see cref="IDatabaseConnectionFactory.CreateDatabaseConnection"/> is called.</param>
		public MockDatabaseConnectionFactory(Guid tenantId, string databaseKey, IDbConnection connection)
			: base(MockBehavior.Strict)
		{
			Safety.AssertArgumentNotNull("databaseKey", databaseKey);
			Safety.AssertArgumentNotNull("connection", connection);

			Expect(x => x.CreateDatabaseConnection(tenantId, databaseKey)).Returns(connection).AtMostOnce();
		}

		#endregion // Constructors

	}
}
